import Vue from 'vue'
import App from './App'
import uView from 'uview-ui'
import store from './store'
import './static/css/icon.css'
//main.js
import commonShare from '@/utils/commonShare.js'
import {toast} from './utils/tools'

Vue.prototype.$shareTitle = '教管壹管控小程序'
Vue.prototype.$toast = toast

Vue.mixin(commonShare)

Vue.use(uView)
Vue.config.productionTip = false

Vue.filter('newDate', function(value) {
	if (value === 0) return '未安装'
	if (value === null) return ''
	if (value === undefined) return ''
	let date = new Date(parseInt(value) * 1000);
	let y = date.getFullYear();
	let m = (date.getMonth() + 1 + '').padStart(2, '');
	let d = (date.getDate() + '').padStart(2, '0');
	let h = date.getHours();
	let minute = date.getMinutes();
	let second = date.getSeconds();
	minute = minute < 10 ? "0" + minute : minute;
	second = second < 10 ? "0" + second : second;
	return `${y}-${m}-${d} ${h}:${minute}:${second}`
})

Vue.filter('computeMinute', function(value) {
	var dataTime = ''
	var h = Math.floor(value / 60)
	value -= h * 60
	if (value == 0) {
		dataTime = h ? `${h}小时` : ''
	} else {
		if (value < 10) {
			value = '0' + value
		}
		dataTime = (h ? `${h}小时` : '') + (value ? `${value}分钟` : '')
	}
	return dataTime
})

Vue.filter('Minute', function(value) {
	var theTime = parseInt(value); // 需要转换的时间秒
	var theTime1 = 0; // 分 
	var theTime2 = 0; // 小时 
	var theTime3 = 0; // 天
	if (theTime > 60) {
		theTime1 = parseInt(theTime / 60);
		theTime = parseInt(theTime % 60);
		if (theTime1 > 60) {
			theTime2 = parseInt(theTime1 / 60);
			theTime1 = parseInt(theTime1 % 60);
			if (theTime2 > 24) {
				//大于24小时
				theTime3 = parseInt(theTime2 / 24);
				theTime2 = parseInt(theTime2 % 24);
			}
		}
	}
	var result = '';
	if (theTime > 0) {
		result = "" + parseInt(theTime) + "秒";
	}
	if (theTime1 > 0) {
		result = "" + parseInt(theTime1) + "分" + result;
	}
	if (theTime2 > 0) {
		result = "" + parseInt(theTime2) + "小时" + result;
	}
	if (theTime3 > 0) {
		result = "" + parseInt(theTime3) + "天" + result;
	}
	return result;
})

Vue.filter('zhDate', function(size) {
	if (!size) return "";
	var num = 1024.00; //byte
	if (size < num) return size + "B";
	if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + "KB"; //kb
	if (size < Math.pow(num, 3)) return (size / Math.pow(num, 2)).toFixed(2) + "MB"; //M
	if (size < Math.pow(num, 4)) return (size / Math.pow(num, 3)).toFixed(2) + "G"; //G
	return (size / Math.pow(num, 4)).toFixed(2) + "T"; //T
})

App.mpType = 'app'

const app = new Vue({
	...App,
	store
})
app.$mount()
